n=int(input())
a=[eval(i) for i in input().split()]
s=0
x=a.index(1)
if a[n-1]==0:
    for i in range(x,n-1):
        if a[i]==1:
            s+=1
        elif a[i-1]==1 and a[i]==0 and a[i+1]==1:
            s+=1
else:
    for i in range(x,n):
        if a[i]==1:
            s+=1
        elif a[i-1]==1 and a[i]==0 and a[i+1]==1:
            s+=1        
print(s)
       

        

